package br.estacio.contatos.client.ui;

import br.estacio.contatos.client.event.SalvarContatoHandler;
import br.estacio.contatos.client.i18n.ContatosConstants;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

public class EditarContactViewImpl extends Composite implements ContatoView {

	private static EditarContactViewImplUiBinder uiBinder = GWT.create(EditarContactViewImplUiBinder.class);

	interface EditarContactViewImplUiBinder extends UiBinder<Widget, EditarContactViewImpl> {
	}
	
	EventBus eventBus;
	
	@UiField
	TextBox nomeTextBox;
	
	@UiField
	TextBox emailTextBox;
	
	@UiField
	TextBox telefoneTextBox;
	
	@UiField
	Button confirmarButton;

	private SalvarContatoHandler salvarContatoHandler;

	private final ContatosConstants contatoConstants;

//	@UiField
//	Hyperlink cancelarHyperlink;
	
	public EditarContactViewImpl(EventBus eventBus, ContatosConstants contatoConstants) {
		this.eventBus = eventBus;
		this.contatoConstants = contatoConstants;
		initWidget(uiBinder.createAndBindUi(this));
	}
	
	@UiHandler("confirmarButton")
	public void salvar(ClickEvent event) {
		salvarContatoHandler.salvarContato();
	}

	@Override
	public void setNome(String nome) {
		nomeTextBox.setText(nome);
	}

	@Override
	public void setEmail(String email) {
		emailTextBox.setText(email);
	}

	@Override
	public void setTelefone(String telefone) {
		telefoneTextBox.setText(telefone);
	}

	@Override
	public String getNome() {
		return nomeTextBox.getText();
	}

	@Override
	public String getEmail() {
		return emailTextBox.getText();
	}

	@Override
	public String getTelefone() {
		return telefoneTextBox.getText();
	}

	@Override
	public void setSalvarHandler(SalvarContatoHandler handler) {
		this.salvarContatoHandler = handler;
	}

	@Override
	public void limparCampos() {
		TextBox campos[] = {nomeTextBox, emailTextBox, telefoneTextBox};
		for (TextBox textBox : campos) {
			textBox.setText("");
		}
	}
	
	public ContatosConstants getContatosConstants() {
		return contatoConstants;
	}

}
